﻿function ClientSyncOfficeWithPlugInService() {
    document.getElementById("divProcessing").innerHTML = Portal.SystemWebParts.Office.Office.GetProcessingText().value;
    setTimeout("RealSyncOfficeWithPlugInService()", 10);
}

function RealSyncOfficeWithPlugInService() {
    retValue = Portal.SystemWebParts.Office.Office.ServerSideSyncOfficeWithPlugInService().value;
    document.getElementById("divProcessing").innerHTML = "";
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
}

function RunFilter()
{
    document.getElementById("divProcessing").innerHTML=Portal.SystemWebParts.Office.Office.GetProcessingText().value;
    setTimeout("RealRunFilter()",10);
}

function RealRunFilter()
{
    PageIndex=0;
    if(document.getElementById("divSelectPage")!=null)
    {
        PageIndex=document.getElementById("divSelectPage").selectedIndex;
    }
    value=Portal.SystemWebParts.Office.Office.GetOffice(PageIndex).value;
    if(value.indexOf("ERROR")!=-1)
    {
        alert(value);
        return;
    }
    document.getElementById("divProcessing").innerHTML="";
    document.getElementById("divOfficeContent").innerHTML=value;
}


function DeleteOffice(OfficeId)
{
    ConfirmMsg=Portal.SystemWebParts.Office.Office.GetConfirmDeleteMsg().value;
    if(confirm(ConfirmMsg)==false)return;
    retValue = Portal.SystemWebParts.Office.Office.ServerSideDeleteOffice(OfficeId).value;
    Portal.SystemWebParts.Office.Office.ServerSideMakeXml().value;
    alert(retValue);
    if(retValue.indexOf("ERROR")!=-1)
    {
        RunFilter();
    }
}


function ClientAddOffice() {
    Url = Portal.SystemWebParts.Office.Office.GetAddOfficeUrl().value;
    window.open(Url, '_blank');
}



function ClientSaveAddOffice() {
    OfficeCode = document.getElementById("txtOfficeCode").value;
    OfficeName = document.getElementById("txtOfficeName").value;
    Description = document.getElementById("txtDescription").value;
    retValue = Portal.SystemWebParts.Office.AddOffice.ServerSideAddOffice(OfficeCode, OfficeName,Description).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    Portal.SystemWebParts.Office.AddOffice.ServerSideMakeXml().value;
    window.close();
}

function ShowClientUpdateUrlForm(OfficeId) {
    Url = Portal.SystemWebParts.Office.Office.GetUpdateOfficeUrl(OfficeId).value;
    window.open(Url, '_blank');
}


function ClientSaveUpdateOffice(OfficeId) {
    Locked = document.getElementById("drpSelectLocked").selectedIndex;
    OfficeCode = document.getElementById("txtOfficeCode").value;
    OfficeName = document.getElementById("txtOfficeName").value;
    Description = document.getElementById("txtDescription").value;
    retValue = Portal.SystemWebParts.Office.UpdateOffice.ServerSideUpdateOffice(OfficeId, OfficeCode, OfficeName, Description, Locked).value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    Portal.SystemWebParts.Office.UpdateOffice.ServerSideMakeXml().value;
    alert(retValue);
    window.close();
}

function ClientMakeRoleFromOffice() {
    document.getElementById("divProcessing").innerHTML = Portal.SystemWebParts.Office.Office.GetProcessingText().value;
    setTimeout("RealClientMakeRoleFromOffice()", 10);
}

function RealClientMakeRoleFromOffice() {
    retValue = Portal.SystemWebParts.Office.Office.ServerSideCreateRoleFromOffice().value;
    if (retValue.indexOf("ERROR") != -1) {
        alert(retValue);
        return;
    }
    alert(retValue);
    document.getElementById("divProcessing").innerHTML = "";
}

function ClientMakeXml() {
    document.getElementById("divProcessing").innerHTML = Portal.SystemWebParts.Office.Office.GetProcessingText().value;
    setTimeout("RealClientMakeXml()", 10);
}

function RealClientMakeXml() {
    rValue = Portal.SystemWebParts.Office.Office.ServerSideMakeXml().value;
    document.getElementById("divProcessing").innerHTML = "";
    if (rValue.indexOf("ERROR") != -1) 
    {
        alert(rValue);
        return;
    }
    else 
    {
        alert(rValue);
    }
}